package com.star.wellconnect.signuplogin;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.star.wellconnect.R;
import com.star.wellconnect.WellConnectActivity;
import com.star.wellconnect.sqlite.AppPreferences;
import com.star.wellconnect.sqlite.Patient;

public class LoggedInFragment extends Fragment{
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
		return inflater.inflate(R.layout.fragment_logged_in, container, false);
	}
	
	@Override
	public void onViewCreated(View view, Bundle savedInstanceState){
		super.onViewCreated(view, savedInstanceState);
		
		TextView username = (TextView) view.findViewById(R.id.username);
		Button cont = (Button) view.findViewById(R.id.cont_button);
		Button logout = (Button) view.findViewById(R.id.logout_button);
		Patient patient = AppPreferences.getPatient(getActivity());
		
		username.setText(this.getResources().getString(R.string.are_you) + " " +
				patient.username + "?");
		cont.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
                Intent intent = new Intent(getActivity(), WellConnectActivity.class);
                startActivity(intent);
			}
		});
		logout.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				AppPreferences.logout(getActivity());
			}
		});
	}

	@Override
	public void onSaveInstanceState(Bundle outState) {
		super.onSaveInstanceState(outState);
	}
}
